#include "Plane3D.h"

Plane3D::Plane3D()
{
	myPoint.Set(0.0f, 0.0f, 0.0f);
	myNormal.Set(0.0f, 0.0f, 0.0f);
	point1 = point2 = point3 = myPoint;
}

Plane3D::Plane3D(const Vector3<float> &aFirstPoint, const Vector3<float> &aSecondPoint, const Vector3<float> &aThirdPoint)
{
	Init(aFirstPoint, aSecondPoint, aThirdPoint);
}

Plane3D &Plane3D::Init(const Vector3<float> &aFirstPoint, const Vector3<float> &aSecondPoint, const Vector3<float> &aThirdPoint)
{
	point1 = aFirstPoint;
	point2 = aSecondPoint;
	point3 = aThirdPoint;
	return Calculate();
}

Plane3D &Plane3D::Init(const Vector3<float> &aPoint,const Vector3<float> &aNormal)
{
	myPoint = aPoint;
	myNormal = aNormal;
	point1 = aPoint;
	point2 = aNormal.Cross(point1);
	point3 = aNormal.Cross(point2);
	return *this;
}

Plane3D &Plane3D::Calculate()
{
	Vector3f v = point2 - point1;
	Vector3f w = point3 - point1;
	myNormal = v.Cross(w);
	myNormal.Normalize();
	myPoint = point1;
	return *this;
}

bool Plane3D::Inside(const Plane3D &aPlane) const
{
	if(myNormal.Dot((aPlane.point1-point1).Normalize()) > 0)
	{
		return true;
	}
	return false;
}

bool Plane3D::Inside(const Vector3f &aPosition) const
{
	if(myNormal.Dot((aPosition-point1).Normalize()) > 0)
	{
		return true;
	}
	return false;
}